/**
 * Created by cells on 2015/12/22.
 */
function progressBar(){
    (function($){
        var $box = $('#box');
        var $bg = $('#bg');
        var $bgcolor = $('#bgcolor');
        var $btn = $('#bt');
        var $text = $('#text');
        var statu = false;
        var ox = 0;
        var lx = 0;
        var left = 0;
        var bgleft = 0;
        $btn.mousedown(function(e){
            lx = $btn.offset().left;
            ox = e.pageX - left;
            statu = true;
        });
        $(document).mouseup(function(){
            statu = false;
        });
        $box.mousemove(function(e){
            if(statu){
                left = e.pageX - ox;
                if(left < 0){
                    left = 0;
                }
                if(left > 800){
                    left = 800;
                }
                $btn.css('left',left);
                $bgcolor.width(left);
                //$text.html('位置:' + parseInt(left/8) + '%');
                if(parseInt(left/8) < 34){
                    $(".product_page .rollimg1").addClass("active").siblings().removeClass('active')
                }else if(parseInt(left/8) < 67){
                    $(".product_page .rollimg2").addClass("active").siblings().removeClass('active')
                }else{
                    $(".product_page .rollimg3").addClass("active").siblings().removeClass('active')
                }
            }
        });
        $bg.click(function(e){
            if(!statu){
                bgleft = $bg.offset().left;
                left = e.pageX - bgleft;
                if(left < 0){
                    left = 0;
                }
                if(left > 800){
                    left = 800;
                }
                $btn.css('left',left);
                $bgcolor.stop().animate({width:left},800);
                //$text.html('位置:' + parseInt(left/2) + '%');
                if(parseInt(left/8) < 34){
                    $(".product_page .rollimg1").addClass("active").siblings().removeClass('active')
                }else if(parseInt(left/8) < 67){
                    $(".product_page .rollimg2").addClass("active").siblings().removeClass('active')
                }else{
                    $(".product_page .rollimg3").addClass("active").siblings().removeClass('active')
                }
            }
        });
    })(jQuery);
}
